﻿using AutoMapper;
using B.W.passport.Application.DTO;
using B.W.passport.Domain;
using B.W.passport.IBaseRepisitory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace B.W.passport.Application.AdminService
{
    public class AddProductService:IAddProductService
    {
        private readonly IBaseRepisitory<Product> ProductRepisitory;
        private readonly IMapper mapper;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="productRepisitory"></param>
        /// <param name="mapper"></param>
        public AddProductService(IBaseRepisitory<Product> productRepisitory, IMapper mapper)
        {
            ProductRepisitory = productRepisitory;
            this.mapper = mapper;
        }
        /// <summary>
        /// 添加商品信息
        /// </summary>
        /// <returns></returns>
        public async Task<APIResult<int>> AddProduct(ProductDTO product)
        {
            APIResult<int> result = new APIResult<int>();
            result.Code = APIEnumsCode.添加成功;
            result.Message = APIEnumsCode.添加成功.ToString();

            var list = mapper.Map<Product>(product);
            await ProductRepisitory.AddAsync(list);

            return result;
        }
    }
}
